﻿@inherits UsersBase

<EditPage @ref="EditPage" Id="user" FixedHeader="@FixedHeader" TItem="Bootstrap.DataAccess.User" SubmitModalTitle="用户编辑窗口" QueryModel="QueryModel" OnQuery="Query" OnAdd="Add" OnDelete="Delete" OnSave="Save" OnResetSearch="ResetSearch">
    <QueryBody>
        <LgbInputText ColumnClass="col-sm-auto" @bind-Value="@context.UserName" maxlength="50" />
        <LgbInputText ColumnClass="col-sm-auto" @bind-Value="@context.DisplayName" maxlength="50" />
    </QueryBody>
    <TableToolbarTemplate>
        <TableToolbarButton class="btn btn-info" Icon="fa fa-bank" Title="分配部门" OnClick="AssignGroups" />
        <TableToolbarButton class="btn btn-warning" Icon="fa fa-sitemap" Title="分配角色" OnClick="AssignRoles" />
    </TableToolbarTemplate>
    <TableHeader>
        <LgbTableHeader TItem="string" @bind-Value="@context.UserName" Sort="true"></LgbTableHeader>
        <LgbTableHeader TItem="string" @bind-Value="@context.DisplayName" Sort="true"></LgbTableHeader>
        <LgbTableHeader TItem="DateTime" @bind-Value="@context.RegisterTime" Sort="true"></LgbTableHeader>
        <LgbTableHeader TItem="DateTime?" @bind-Value="@context.ApprovedTime" Sort="true"></LgbTableHeader>
        <LgbTableHeader TItem="string" @bind-Value="@context.ApprovedBy" Sort="true"></LgbTableHeader>
        <LgbTableHeader TItem="string" @bind-Value="@context.Description" Sort="true"></LgbTableHeader>
    </TableHeader>
    <RowTemplate>
        <td>@context.UserName</td>
        <td>@context.DisplayName</td>
        <td>@context.RegisterTime.ToString("yyyy-MM-dd HH:mm:ss")</td>
        <td>@(context.ApprovedTime?.ToString("yyyy-MM-dd HH:mm:ss") ?? "-")</td>
        <td>@context.ApprovedBy</td>
        <td>@context.Description</td>
    </RowTemplate>
    <EditTemplate>
        <div class="row">
            <LgbInputText @bind-Value="@context.UserName" placeholder="不可为空，16字以内" maxlength="16">
                <RequiredValidator />
                <StringLengthValidator Length="16" />
            </LgbInputText>
            <LgbInputText @bind-Value="@context.DisplayName" placeholder="不可为空，20字以内" maxlength="20">
                <RequiredValidator />
                <StringLengthValidator Length="20" />
            </LgbInputText>
            <LgbInputText InputType="password" @bind-Value="@context.Password" autocomplete="off" placeholder="不可为空，16字以内" maxlength="16">
                <RequiredValidator />
                <StringLengthValidator Length="16" />
            </LgbInputText>
            <LgbInputText InputType="password" @bind-Value="@context.NewPassword" autocomplete="off" placeholder="与登录密码一致" maxlength="16">
                <RequiredValidator />
                <StringLengthValidator Length="16" />
                <EqualToValidator @bind-Value="@context.Password" />
            </LgbInputText>
        </div>
    </EditTemplate>
</EditPage>

<AssignModal @ref="AssignGroupModal" TItem="Bootstrap.DataAccess.Group" Id="user-group" Title="部门授权窗口" OnSave="SaveGroups">
    <ItemTemplate>
        <Checkbox TItem="Bootstrap.DataAccess.Group" Item="@context" Text="@context.GroupName" SetCheckCallback="SetGroupCheck" OnClick="OnGroupClick" />
    </ItemTemplate>
</AssignModal>

<AssignModal @ref="AssignRoleModal" TItem="Bootstrap.DataAccess.Role" Id="user-role" Title="角色授权窗口" OnSave="SaveRoles">
    <ItemTemplate>
        <Checkbox TItem="Bootstrap.DataAccess.Role" Item="@context" Text="@context.RoleName" SetCheckCallback="SetCheck" OnClick="OnClick" />
    </ItemTemplate>
</AssignModal>
